#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e3+3;
int t,n,m,l,V,d[maxn],v[maxn],a[maxn],p[maxn],b[maxn];
bool vis[maxn];
int sum,cnt;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
		int sum=0,cnt=0;
		cin>>n>>m>>l>>V;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>v[i]>>a[i];
			b[a[i]]++;
		}
		sort(d+1,d+n+1);
		for(int i=1;i<=m;i++){
			cin>>p[i];
		}
		sort(p+1,p+m+1);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(b[0]==n){
				     if(v[i]>=V) {
					    cnt++;
					    vis[i]=1;
					    if(d[i]<=p[j]&&vis[i]==1){
							sum++;
							vis[i]=0;
						}
				     }
			    }
			}
		}
		cout<<cnt<<" "<<m-sum<<endl;
	}
	return 0;
}
